<template>
  <el-form label-width="6vw">
    <el-form-item label="标签类型">
      <el-select v-model="config.reelType" placeholder="标签类型">
        <el-option
          v-for="item of reelType"
          :key="item.value"
          :label="item.label + '标签'"
          :value="item.value"
        />
      </el-select>
    </el-form-item>
    <el-form-item :label="$t('editFormula.printTemplate')">
      <el-select v-model="config.labelTemplate" @change="labelChange">
        <el-option
          v-for="item of labelTemp"
          :Key="item.label"
          :value="item.label"
          :label="item.label"
        ></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="标签打印配置">
      <el-button
        @click="editPrint(config.labelPrintParam, config)"
        type="primary"
        size="small"
        style="width: 100%"
        >打印机参数配置</el-button
      >
    </el-form-item>

    <el-form-item :label="$t('editFormula.needSeal')">
      <el-switch
        v-model="config.qaStamp"
        active-text="是"
        inactive-text="否"
      ></el-switch>
    </el-form-item>
    <template v-if="config.qaStamp">
      <el-form-item :label="$t('editFormula.sealNo')">
        <el-input v-model="config.qaStampCode"></el-input>
      </el-form-item>
      <!-- <el-form-item :label="$t('editFormula.sealDescribe')">
        <el-input v-model="config.qaStampDesc"></el-input>
      </el-form-item> -->
      <el-form-item :label="$t('editFormula.sealX')">
        <el-input-number v-model="config.qaStampX"></el-input-number>
      </el-form-item>
      <el-form-item :label="$t('editFormula.sealY')">
        <el-input-number v-model="config.qaStampY"></el-input-number>
      </el-form-item>
      <el-form-item :label="$t('editFormula.sealRotation')">
        <el-input-number v-model="config.qaStampAngle"></el-input-number>
      </el-form-item>
    </template>

    <printConfig
      :options="printOption"
      @closeDialog="printOption.show = false"
    />
  </el-form>
</template>
<script setup>
import { useI18n } from "vue-i18n";
import { reelType } from "@/store/editStore.js";
import editStore from "@/store/editStore";
import { computed, reactive } from "vue";
import printConfig from "./printConfig.vue";
let props = defineProps({
  config: {
    type: Object,
    default: () => ({}),
  },
});

const store = editStore();
const { t: $t } = useI18n();
const printOption = reactive({
  show: false,
  data: [],
});

let labelTemp = computed(() => {
  let stand = store.reelConfig.packingLabelCode;
  if (!stand) return [];
  return store.labelTemplate[stand];
});

function labelChange(label) {
  labelTemp.value.forEach((item) => {
    if (item.label == label) {
      props.config.picName = item.img;
    }
  });
}

function editPrint(data, config) {
  if (data[0]) {
    data[0].id = config.id;
    data[0].code = config.code;
  }
  printOption.show = true;
  printOption.data = props.config.labelPrintParam;
}
</script>
<style scoped lang="scss">
.el-form-item {
  margin-bottom: 10px;
}
.el-input-number {
  width: 100%;
}
</style>
